﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.SqlTypes;
using System.Data;

namespace Test2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Incepe testul.\n");

            try
            {
                Utilizator utilizator=Utilizator.autentificaUtilizator("Radu","0000");

                //utilizator.creeazaUtilizator("Amador","1234"); Merge!

                //utilizator.stergeUtilizator("Adelina"); Merge!

                string[] detaliiProdus ={
                                            "Smecherie",//1 nume produs
                                            "2",//2 id brand
                                            "1010",//3 stoc
                                            "smartphone",//4 dc
                                            "mem,cpu",//5 dc
                                            "3",//6 id_parinte
                                            @"C:\Users\james bond\Pictures\LifeFrame\1.jpg"//7 imagine
                                       };
               // utilizator.adaugaProdus(detaliiProdus); //Merge!

                utilizator.daPoza("Smecherie");

                //utilizator.salveazaProdusEditat(detaliiProdus); Merge!

                //utilizator.stergeTemporarProdusul("p2"); Merge!

                //utilizator.stergeDefinitivProdusul("p2"); //Nu merge!

                //Console.WriteLine(utilizator.cautaProdus("Smecherie")); Merge!

                //List<string> toateProdusele = utilizator.toateProduseleExistente();
                //foreach (var s in toateProdusele)
                //    Console.WriteLine(s);

                //DataTable dt=utilizator.produseFiltrate("[nume_produs] like 'P%'"); 

                ////DataTable dt=utilizator.produseSortate("[nume_produs] ASC");
                //foreach (DataRow dr in dt.Rows)
                //    Console.WriteLine("{0}",dr["nume_produs"]); 




                //using (SqlConnection connection = new SqlConnection())
                //{
                //    connection.ConnectionString = ConfigurationManager.ConnectionStrings["Test"].ConnectionString;

                //    //string sql =
                //    //    "INSERT INTO Utilizatori_ (nume_utilizator,parola) values(@nume,@parola)";

                //    SqlParameter par = new SqlParameter();
                //    par.Value = "Iphone 8";
                //    par.ParameterName = "@nume_vechi";

                //    SqlParameter par1 = new SqlParameter();
                //    par1.Value = "Iphone 1001";
                //    par1.ParameterName = "@nume_produs";

                //    SqlParameter par2 = new SqlParameter();
                //    par2.Value = 1;
                //    par2.ParameterName = "@brand_id";

                //    SqlParameter par3 = new SqlParameter();
                //    par3.Value = 200;
                //    par3.ParameterName = "@stoc";

                //    SqlParameter par4 = new SqlParameter();
                //    par4.Value = "aaaaaaaaaaaa";
                //    par4.ParameterName = "@descriere_client";

                //    SqlParameter par5 = new SqlParameter();
                //    par5.Value = "xxxxx";
                //    par5.ParameterName = "@descriere_continut";

                //    SqlParameter par6 = new SqlParameter();
                //    par6.Value = 2;
                //    par6.ParameterName = "@id_parinte";

                //    connection.Open();

                //    using (SqlTransaction tran = connection.BeginTransaction())
                //    {
                //        try
                //        {
                //            SqlDataAdapter dataAdapter = new SqlDataAdapter("produsEditat", connection);

                //            dataAdapter.UpdateCommand = new SqlCommand("produsEditat", connection);
                //            dataAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
                //            //dataAdapter.UpdateCommand.CommandText = "salveazaModificariProdus";

                //            //SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);

                //            dataAdapter.UpdateCommand.Parameters.Add(par);
                //            dataAdapter.UpdateCommand.Parameters.Add(par1);
                //            dataAdapter.UpdateCommand.Parameters.Add(par2);
                //            dataAdapter.UpdateCommand.Parameters.Add(par3);
                //            dataAdapter.UpdateCommand.Parameters.Add(par4);
                //            dataAdapter.UpdateCommand.Parameters.Add(par5);
                //            dataAdapter.UpdateCommand.Parameters.Add(par6);

                //            dataAdapter.UpdateCommand.Transaction = tran;
                //           // builder.GetUpdateCommand();

                //            dataAdapter.UpdateCommand.ExecuteNonQuery();

                //            tran.Commit();

                //            Console.WriteLine("Produs adaugat cu succes.\n");
                //        }
                //        catch (Exception ex)
                //        {
                //            Console.WriteLine("Exceptie la adaugarea unui produs.+{0}", ex.ToString());
                //            tran.Rollback();
                //        }

                //    }
                //}

            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.ToString());
            }
            finally
            {
                Console.WriteLine("\n*****************FINAL PROGRAM********************\n");
            }
            
        }
    }
}
